package com.example.controller;

import com.example.domain.dto.DepartmentDTO;
import com.example.domain.po.Course;
import com.example.domain.po.Department;
import com.example.domain.vo.CourseVo;
import com.example.domain.vo.DepartmentVo;
import com.example.service.DepartmentService;
import com.example.util.PageBean;
import com.example.util.Result;
import com.github.pagehelper.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.io.IOException;
import java.util.List;

@RestController
@RequestMapping("/department")
public class DepartmentController {
    @Autowired
    private DepartmentService departmentService;

    @GetMapping
    public Result<List<Department>> list() {
        return Result.success(departmentService.list());
    }


    @GetMapping("/singleList")
    public Result<PageBean<Department>> singleList(
            Integer pageNum,
            Integer pageSize,
            String name
    ) {
        return Result.success(departmentService.singleList(pageNum, pageSize, name));
    }


    @GetMapping("/page")
    public Result<PageBean<DepartmentVo>> page(
            Integer pageNum,
            Integer pageSize,
            Integer hospitalId,
            String name
    ) {
        return Result.success(departmentService.page(pageNum, pageSize, hospitalId, name));
    }


    @GetMapping("/findById")
    public Result<Department> findById(Integer id) {
        return Result.success(departmentService.findById(id));
    }

    @GetMapping("/findByHospitalId/{id}")
    public Result<List<Department>> findByHospitalId(@PathVariable Integer id) {
        return Result.success(departmentService.findByHospitalId(id));
    }

    @PostMapping("/save")
    public Result<String> save(@RequestBody DepartmentDTO departmentDTO) throws IOException {
        String s = departmentService.save(departmentDTO);
        return Result.success(s);
    }


    @GetMapping("/del")
    public Result<String> del(Integer id) {
        departmentService.del(id);

        return Result.success("删除成功");
    }

}
